package com.sgb.kjwl.view.ui.adapter.self.publish;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.user.GoodsStateEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class GoodsStateAdapter extends BaseRecycleAdapter<GoodsStateEntity> {

    private TextView contentView;
    private TextView timeView;
    private String type;
    private TextView tvItemUp;
    private TextView tvItemCancel;
    private TextView tvItemEdit;
    private Context context;
    private TextView priceUnit;

    public GoodsStateAdapter(Context context, List<GoodsStateEntity> datas, String type) {
        super(context, R.layout.item_goods_state_new, datas);
        this.type = type;
        this.context = context;
    }

    @Override
    public void convert(ItemViewHolder holder, final GoodsStateEntity entity) {
        holder.setBinding(BR.viewModel, entity);
//        contentView = holder.getItem().findViewById(R.id.content_view);
//        timeView = holder.getItem().findViewById(R.id.time_view);
        tvItemUp = holder.getItem().findViewById(R.id.tv_item_up);
        tvItemCancel = holder.getItem().findViewById(R.id.tv_item_cancel);
        tvItemEdit = holder.getItem().findViewById(R.id.tv_item_edit);
//        priceUnit = holder.getItem().findViewById(R.id.price_unit);

//        priceUnit.setText("元/" + entity.getUnit());

//        contentView.setText(entity.getBrand() + " | " + entity.getAddress());
//        timeView.setText("更新时间：" + entity.getUpdateTime());

        if ("UP".equals(type)) {
            tvItemUp.setText("下架");
        } else {
            tvItemUp.setText("上架");
        }

        tvItemUp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                editClickListener.onUpClick(entity.getId(), holder.getPosition());
            }
        });

        tvItemCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                editClickListener.onCancelClick(entity.getId(), holder.getPosition());
            }
        });

        tvItemEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                editClickListener.onEditeClick(entity, holder.getPosition());
            }
        });
    }

    private GoodsStateAdapter.onEditClickListener editClickListener;

    public void setonEditClick(GoodsStateAdapter.onEditClickListener editClickListener) {
        this.editClickListener = editClickListener;
    }

    public interface onEditClickListener {
        void onCancelClick(String id, int position);

        void onUpClick(String id, int position);

        void onEditeClick(GoodsStateEntity entity, int position);
    }
}
